{
    "cells": [
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "367a6eae",
            "metadata": {},
            "outputs": [],
            "source": [
                "import logging\n",
                "import sys\n",
                "\n",
                "logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
                "logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "21d03e9b-8a47-45b2-ab27-295b7397ecad",
            "metadata": {},
            "outputs": [],
            "source": [
                "from llama_index import GPTSimpleVectorIndex, TwitterTweetReader\n",
                "from IPython.display import Markdown, display\n",
                "import os"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "ef5d2334-9661-4648-a823-a335ea277826",
            "metadata": {},
            "outputs": [],
            "source": [
                "# create an app in https://developer.twitter.com/en/apps\n",
                "BEARER_TOKEN = \"<bearer_token>\""
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "1d6a1153-1383-4aaf-b39d-72c1fc9cc428",
            "metadata": {},
            "outputs": [],
            "source": [
                "# create reader, specify twitter handles\n",
                "reader = TwitterTweetReader(BEARER_TOKEN)\n",
                "documents = reader.load_data([\"@twitter_handle1\"])"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "ca319024-88e7-424f-b1d8-4daa06c6bc6a",
            "metadata": {},
            "outputs": [],
            "source": [
                "index = GPTSimpleVectorIndex.from_documents(documents)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "78680a17-9088-419e-97cf-ac3d5783a709",
            "metadata": {},
            "outputs": [],
            "source": [
                "# set Logging to DEBUG for more detailed outputs\n",
                "response = index.query(\"<query_text>\")"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "2f0f92a7-cdd9-478f-9765-0a122d6e8508",
            "metadata": {},
            "outputs": [],
            "source": [
                "display(Markdown(f\"<b>{response}</b>\"))"
            ]
        }
    ],
    "metadata": {
        "kernelspec": {
            "display_name": "Python 3 (ipykernel)",
            "language": "python",
            "name": "python3"
        },
        "language_info": {
            "codemirror_mode": {
                "name": "ipython",
                "version": 3
            },
            "file_extension": ".py",
            "mimetype": "text/x-python",
            "name": "python",
            "nbconvert_exporter": "python",
            "pygments_lexer": "ipython3",
            "version": "3.11.1"
        }
    },
    "nbformat": 4,
    "nbformat_minor": 5
}